library(nat)
library(neuprintr)
library(tidyverse)
library(ggraph)
library(plotly)
library(dplyr)
library(pbapply)
library(tidygraph)
library(gridExtra)
library(neuprintrExtra)
library(paletteer)
library(alphahull)
# Go to the neurpintR-notebooks directory before loading these functions
source("visualizeConnectivityTables.R")
# source("neuprintQueryUtils.R")
source("R/table2ggraphUtils.R")
source("R/connectivityMatricesTools.R")
# source("InputOutputByTypeUtils.R")
# source("R/rois.R")
# source("R/supertypeUtils.R")
source("colorCodeLookup.R")
source("pathways.R")
source("inputOutputRegionsVis.R")
source("GetNeuronsInRoi.R")
source("FBNetworkVisUtils.R")
source("CX_ContextualAnalysisUtils.R")
options(nat.plotengine = 'rgl')
# Directory to save data to.
SaveDir = "/Users/danc/Dropbox (HHMI)/WorkDrop/Data/FIBSEM_Analysis"
# Directory to save plots to.
PlotDir = "/Users/danc/Dropbox (HHMI)/WorkDrop/Data/FIBSEM_Analysis"
if (!dir.exists(SaveDir)){dir.create(SaveDir)}
if (!dir.exists(PlotDir)){dir.create(PlotDir)}
# neuprint_login()
neuprint_login(config=httr::set_config(httr::config(ssl_verifypeer = 0L)))
roisH <- getRoiTree()
roiSelection <- selectRoiSet(roisH,default_level=1,exceptions=list("CX"=2))
MBON_Names <- neuprint_search("MBON.*")
# Find the postsynaptic partners of all MBONs
MBON_PostConnections <- getConnectionTable(MBON_Names,synapseType = "POST") ## Keeping the default threshold (3)
# Selecting CX types as those present in Romain's list.
CXTypes <- supertype(read_csv("/Users/danc/Dropbox (HHMI)/WorkDrop/Manuscripts/FIBSEM CX Paper Jan 2020/CX-cell-types060920") %>% rename(databaseType=n.type))
Parsed with column specification:
cols(
n.type = [31mcol_character()[39m
)
MBON_targets <- unique(MBON_PostConnections$type.to)
# Pick MBON targets in the CX
MBONCXTargetsL <- MBON_targets[MBON_targets %in% CXTypes$databaseType]
MBONCXTargets <- getTypesTable(MBONCXTargetsL)
# Pick MBON targets not in the CX
MBONnonCXTargetsL <- MBON_targets[!(MBON_targets %in% CXTypes$databaseType)]
MBONnonCXTargetsL <- na.omit(MBONnonCXTargetsL)
# Exclude MBONs from this list
MBONnonCXTargetsL <- MBONnonCXTargetsL[!(MBONnonCXTargetsL %in% MBON_Names$type)]
MBONnonCXTargets <- getTypesTable(MBONnonCXTargetsL)
# Find the postsynaptic partners of MBON non-CX non-MBON targets
MBON_2ndaryPostConnections <- getConnectionTable(MBONnonCXTargets$bodyid,synapseType = "POST") ## Keeping the default threshold (3)
# Find the MBON secondary targets in the CX
MBONCX2ndaryTargetsL <- unique(MBON_2ndaryPostConnections$type.to)[unique(MBON_2ndaryPostConnections$type.to) %in% CXTypes$databaseType]
MBONCX2ndaryTargets <- getTypesTable(MBONCX2ndaryTargetsL)
MBONTargetBag <- buildInputsOutputsByType(MBONCXTargets,slctROI=unique(roiSelection$roi))
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
MBONnonCXTargetBag <- buildInputsOutputsByType(MBONnonCXTargets,slctROI=unique(roiSelection$roi))
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
MBON2ndaryTargetBag <- buildInputsOutputsByType(MBONCX2ndaryTargets,slctROI=unique(roiSelection$roi))
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
MBONTargetBagLat <- lateralizeInputOutputList(MBONTargetBag)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
MBONnonCXTargetBagLat <- lateralizeInputOutputList(MBONnonCXTargetBag)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
MBON2ndaryTargetBagLat <- lateralizeInputOutputList(MBON2ndaryTargetBag)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
MBONTargetInp <- MBONTargetBagLat$inputs %>% filter(startsWith(type.from,"MBON") & grepl("_R",type.to))
MBON2ndaryTargetInp <- MBON2ndaryTargetBagLat$inputs %>% filter((databaseType.from %in% MBONnonCXTargetsL) & grepl("_R",type.to))
# Filter MBONnonCXTargetBagLat$input from MBONs to *_R
MBONnonCXTargetInp <- MBONnonCXTargetBagLat$inputs %>% filter(startsWith(type.from,"MBON") & grepl("_R",type.to))
# Filter MBONnonCXTargetBagLat$ouputs from MBONnonCXTargetInp$type.to to CX_R
MBONnonCXTargetR2CXRtab <- MBONnonCXTargetBagLat$outputs %>% filter(type.from %in% MBONnonCXTargetInp$type.to & databaseType.to %in% CXTypes$databaseType & grepl("_R",type.to))
# Filter MBONnonCXTargetInp by type.to with CX_R targets
MBON2nonCXTargetRtab <- MBONnonCXTargetInp %>% filter(type.to %in% MBONnonCXTargetR2CXRtab$type.from)
MBONTargetInputCombined <- combineRois(MBONTargetBagLat,unique(MBONTargetInp$roi),newRoi="MBON outputs")
`summarise()` regrouping output by 'from', 'to', 'name.from', 'name.to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
`summarise()` regrouping output by 'from', 'to', 'name.from', 'name.to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3', 'roi', 'outputContributionTotal', 'outputContribution' (override with `.groups` argument)
`summarise()` regrouping output by 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3', 'roi', 'outputContributionTotal' (override with `.groups` argument)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3', 'roi', 'outputContributionTotal', 'outputContribution' (override with `.groups` argument)
`summarise()` regrouping output by 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3', 'roi', 'outputContributionTotal' (override with `.groups` argument)
MBONTargetInpC <- MBONTargetInputCombined$inputs %>% filter(startsWith(type.from,"MBON") & grepl("_R",type.to)) %>%
group_by(roi,type.to) %>% mutate(totalMBContribution = sum(weightRelative)) %>%
ungroup() %>%
arrange(desc(totalMBContribution)) %>%
mutate(type.to = factor(type.to,levels=unique(type.to)))## Filter MBON to right CX neurons (some of the left ones can be cut)
plotConnMat_MBON_CX_Romain <- plotConnectivityMatrix(MBONTargetInpC,byGroup="type")
print(plotConnMat_MBON_CX_Romain)
ggsave("MBON_CX_ConnectionsByType_weightRelative_Romain.eps", plot=plotConnMat_MBON_CX_Romain, device="eps", path=PlotDir, scale=1,
width=11, height=8, units="in", dpi=300, limitsize=TRUE)
inputProportions <- ggplot(MBONTargetInpC,aes(x=type.to)) + geom_col(aes(y=weightRelative,fill=type.from)) + scale_fill_manual(values=typesPalette(unique(MBONTargetInpC$type.from)),name="MBON types",guide=guide_legend(ncol=2)) + theme_classic() + theme(axis.text.x = element_text(angle = 90)) + labs(y="Relative weight in input regions",x="Type")
print(inputProportions)
ggsave("CXfromMBON_InputProportionsByType_weightRelative_Romain.eps", plot=inputProportions, device="eps", path=PlotDir, scale=1,
width=11, height=8, units="in", dpi=300, limitsize=TRUE)
# Combine rois based on MBON2nonCXTargetRtab$roi and add a new roi for MBON outputs
MBON2nonCXTargetInputCombined <- combineRois(MBONnonCXTargetBagLat,unique(MBON2nonCXTargetRtab$roi),newRoi="MBON outputs")
`summarise()` regrouping output by 'from', 'to', 'name.from', 'name.to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
`summarise()` regrouping output by 'from', 'to', 'name.from', 'name.to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3', 'roi', 'outputContributionTotal', 'outputContribution' (override with `.groups` argument)
`summarise()` regrouping output by 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3', 'roi', 'outputContributionTotal' (override with `.groups` argument)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3', 'roi', 'outputContributionTotal', 'outputContribution' (override with `.groups` argument)
`summarise()` regrouping output by 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'previous.type.to', 'previous.type.from', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3', 'roi', 'outputContributionTotal' (override with `.groups` argument)
# Sort MBON to non-CX non-MBON _R connections by totalMBContribution descending
MBON2nonCXTargetRInpCombSort <- MBON2nonCXTargetInputCombined$inputs %>% filter(startsWith(type.from,"MBON") & grepl("_R",type.to)) %>%
group_by(roi,type.to) %>% mutate(totalMBContribution = sum(weightRelative)) %>% ungroup() %>% arrange(desc(totalMBContribution)) %>%
mutate(type.to = factor(type.to,levels=unique(type.to)))
# Filter MBON2nonCXTargetInputCombined$ouputs from MBON2nonCXTargetRInpCombSort$type.to to CX_R
MBONnonCXTargetR2CXRInpCombined <- MBON2nonCXTargetInputCombined$outputs %>% filter(type.from %in% MBON2nonCXTargetRInpCombSort$type.to & databaseType.to %in% CXTypes$databaseType & grepl("_R",type.to))
# Filter MBON2nonCXTargetRInpCombSort by type.to with CX_R targets
MBON2nonCXwCXRTgtInpCombSort <- MBON2nonCXTargetRInpCombSort %>% filter(type.to %in% MBONnonCXTargetR2CXRInpCombined$type.from)
plot_MBON2nonCXwCXRTgtInpCombSort <- plotConnectivityMatrix(MBON2nonCXwCXRTgtInpCombSort,byGroup="type")
print(plot_MBON2nonCXwCXRTgtInpCombSort)
ggsave("MBON2nonCXnonMBONTgtRwCXRTgt_InpCombinedSorted.eps", plot=plot_MBON2nonCXwCXRTgtInpCombSort, device="eps", path=PlotDir, scale=1,
width=11, height=8, units="in", dpi=300, limitsize=TRUE)
inputProportions_MBON2nonCXwCXRTgtInpCombSort <- ggplot(MBON2nonCXwCXRTgtInpCombSort,aes(x=type.to)) + geom_col(aes(y=weightRelative,fill=type.from)) + scale_fill_manual(values=typesPalette(unique(MBON2nonCXwCXRTgtInpCombSort$type.from)),name="MBON types",guide=guide_legend(ncol=2)) + theme_classic() + theme(axis.text.x = element_text(angle = 90)) + labs(y="Relative weight in input regions",x="Type")
47 levels in your palette, this is likely too many.
print(inputProportions_MBON2nonCXwCXRTgtInpCombSort)
ggsave("MBON2nonCXnonMBONTgtRwCXRTgt_InputProportionsCombinedSorted.eps", plot=inputProportions_MBON2nonCXwCXRTgtInpCombSort, device="eps", path=PlotDir, scale=1,
width=11, height=8, units="in", dpi=300, limitsize=TRUE)
# Pull significant MBON2nonCXwCXRTgtInpCombSort connections based on "totalMBContribution"
StrongMBON2nonCXwCXRTgtInpCombSort <- MBON2nonCXwCXRTgtInpCombSort %>% filter(totalMBContribution > 0.05)
# Filter MBONnonCXTargetR2CXRtab by type.from among StrongMBON2nonCXwCXRTgtInpCombSort$type.to and weightRelative > 0.01
StrongMBONnonCXTargetR2CXRtab <- MBONnonCXTargetR2CXRtab %>% filter(type.from %in% StrongMBON2nonCXwCXRTgtInpCombSort$type.to & weightRelative > 0.01)
# Filter StrongMBON2nonCXwCXRTgtInpCombSort for those connecting to StrongMBONnonCXTargetR2CXRtab$type.from
StrongMBON2nonCXwCXRTgtInpCombSort <- StrongMBON2nonCXwCXRTgtInpCombSort %>% filter(type.to %in% StrongMBONnonCXTargetR2CXRtab$type.from)
# Make a combined table
StrongMBON2nonCXwCXRTgtTable <- StrongMBON2nonCXwCXRTgtInpCombSort %>% select(type.from,type.to,weightRelative)
StrongMBONnonCXTgtR2CXRTable <- StrongMBONnonCXTargetR2CXRtab %>% select(type.from,type.to,weightRelative)
StrongMBON2nonCXR2CXRTgtComboTable <- bind_rows(StrongMBON2nonCXwCXRTgtTable,StrongMBONnonCXTgtR2CXRTable, .id = NULL)
# Set up the layout for the pathway plot
types <- unique(c(unique(as.vector(StrongMBON2nonCXwCXRTgtTable$type.from)), unique(as.vector(StrongMBONnonCXTgtR2CXRTable$type.from)),
unique(as.vector(StrongMBONnonCXTgtR2CXRTable$type.to))))
numTypes <- length(types)
numMBONs <- length(unique(as.vector(StrongMBON2nonCXwCXRTgtTable$type.from)))
numMidNodes <- length(unique(as.vector(StrongMBONnonCXTgtR2CXRTable$type.from)))
numCXtargets <- length(unique(as.vector(StrongMBONnonCXTgtR2CXRTable$type.to)))
xyLookup = data.frame(type = types, x = c(rep(-1,times = numMBONs), rep(0,times = numMidNodes), rep(1,times = numCXtargets)),
y = c(seq(-1,1,length.out = numMBONs), seq(-1,1,length.out = numMidNodes), seq(-1,1,length.out = numCXtargets)))
# Graph the TypeToType ConnTable using the lookupTable
StrongMBON2nonCXR2CXRTgtComboPath <- graphConTab_old(StrongMBON2nonCXR2CXRTgtComboTable,xyLookup,FALSE,TRUE)
StrongMBON2nonCXR2CXRTgtComboPath <- StrongMBON2nonCXR2CXRTgtComboPath + scale_y_reverse()
print(StrongMBON2nonCXR2CXRTgtComboPath)
ggsave("StrongMBON2nonCXR2CXRTgtComboPath.svg", plot=StrongMBON2nonCXR2CXRTgtComboPath, device="svg", path=PlotDir, scale=1,
width=30, height=45, units="in", dpi=300, limitsize=FALSE)
# Cluster the tables by type.from and type.to
StrongMBON2nonCXwCXRTgt_Type2Type_clustered <- plotCorrMatCluster(PlotDir,StrongMBON2nonCXwCXRTgtTable,'StrongMBON2nonCXwCXRTgt_Type2Type')
Using weightRelative as value column: use value.var to override.
StrongMBONnonCXTgtR2CXR_Type2Type_clustered <- plotCorrMatCluster(PlotDir,StrongMBONnonCXTgtR2CXRTable,'StrongMBONnonCXTgtR2CXR_Type2Type')
Using weightRelative as value column: use value.var to override.
Aggregation function missing: defaulting to length
StrongMBON2nonCXwCXRTgtInpCombSort_CosDist <- cosDistClusterPlot(PlotDir,StrongMBON2nonCXwCXRTgtInpCombSort,"StrongMBON2nonCXwCXRTgtInpCombSort")
StrongMBONnonCXTargetR2CXR_CosDist <- cosDistClusterPlot(PlotDir,StrongMBONnonCXTargetR2CXRtab,"StrongMBONnonCXTargetR2CXR")
# Pull significant MBONTargetInpC connections based on "totalMBContribution"
StrongMBONTargetInpC <- MBONTargetInpC %>% filter(totalMBContribution > 0.05)
StrongMBON2CX_TargetsType <- unique(as.vector(StrongMBONTargetInpC$databaseType.to))
StrongMBON2CX_TargetNeurons <- getTypesTable(StrongMBON2CX_TargetsType)
# head(StrongMBON2CX_TargetNeurons)
# Find the MBON bodyids
StrongMBON2CX_FromType <- unique(as.vector(StrongMBONTargetInpC$databaseType.from))
StrongMBON2CX_FromNeurons <- getTypesTable(StrongMBON2CX_FromType)
# head(StrongMBON2CX_FromNeurons)
# Find neuron to neuron connection table for strong direct MBON to CX connections
StrongMBON2CX_ConnTable <- getConnectionTable_forSubset(StrongMBON2CX_FromNeurons$bodyid, StrongMBON2CX_TargetNeurons$bodyid)
# Arrange StrongMBON2CX_ConnTable in the order of StrongMBONTargetInpC$databaseType.to
StrongMBON2CX_ConnTable$type.to <- factor(StrongMBON2CX_ConnTable$type.to,levels=unique(StrongMBONTargetInpC$databaseType.to),ordered=TRUE)
StrongMBON2CX_ConnTable <- arrange(StrongMBON2CX_ConnTable,type.to)
# Plot StrongMBON2CX_ConnTable
plotStrongMBON2CX_ConnTable <- plotConnectivityMatrix(StrongMBON2CX_ConnTable,byGroup="id")
print(plotStrongMBON2CX_ConnTable)
ggsave("plotStrongMBON2CX_ConnTable.eps", plot=plotStrongMBON2CX_ConnTable, device="eps", path=PlotDir, scale=1,
width=11, height=8, units="in", dpi=300, limitsize=TRUE)
# Set up the layout for the pathway plot
types <- unique(c(unique(as.vector(StrongMBONTargetInpC$type.from)),unique(as.vector(StrongMBONTargetInpC$type.to))))
numFrom <- length(unique(as.vector(StrongMBONTargetInpC$type.from)))
numTo <- length(unique(as.vector(StrongMBONTargetInpC$type.to)))
xyLookup = data.frame(type = types, x = c(rep(-1,times = numFrom),rep(0,times = numTo)), y = c(seq(-1,1,length.out = numFrom), seq(-1,1,length.out = numTo)))
# Graph the TypeToType ConnTable using the lookupTable
StrongMBONTargetInpCdf <- StrongMBONTargetInpC
StrongMBONTargetInpCdf$type.to <- as.vector(StrongMBONTargetInpCdf$type.to)
gg_MBON2TargetTab <- graphConTab_old(StrongMBONTargetInpCdf,xyLookup,FALSE,TRUE)
# gg_MBON2TargetTab <- graphConTabPolyChrome(StrongMBONTargetInpCdf,xyLookup,FALSE,TRUE)
gg_MBON2TargetTab <- gg_MBON2TargetTab + scale_y_reverse()
print(gg_MBON2TargetTab)
ggsave("StrongMBON2CXtargetsTab.svg", plot=gg_MBON2TargetTab, device="svg", path=PlotDir, scale=1,
width=11, height=8, units="in", dpi=300, limitsize=TRUE)
Notes: 1) MBON05 has no branches ipsilateral to the cell body, only contralateral. FB4R only has dendrites ipsilateral to cell body. Therefore, only MBON05_L (not MBON05_R) makes synapses onto FB4R_R. 2) MBON09 has bilateral branches, but only makes contact with ipsilateral FB4R, i.e., MBON09_R onto FB4R_R. 3) MBON21 has bilateral branches, and synapses onto FB4R bilaterally. 4) MBON04 has bilateral branches, but more contralaterally relative to the name (although the *_L cell body is just off to the midline on the right side). 5) MBON12R and MBON13R only have branches ipsilateral to the cell body. 6) MBON03 has bilateral branches, but more contralaterally relative to the name. 7) MBON22 has ipsilateral branches in the calyz and bilateral branches in SIP/SMP. 8) MBON30 has bilateral branches, but more ipsilateral to the cell body.
# Find the postsynaptic partners of StrongMBON2CX_TargetNeurons
StrongMBON2CX_TargetsCnctTable <- getConnectionTable(StrongMBON2CX_TargetNeurons,synapseType="POST")
# head(StrongMBON2CX_TargetsCnctTable)
StrongMBON2CXTargetsToPostInFB <- getConnectionTable_forSubset(StrongMBON2CX_TargetNeurons$bodyid, StrongMBON2CX_TargetsCnctTable$to,"FB")
# Arrange StrongMBON2CXTargetsToPostInFB in the order of StrongMBONTargetInpC$databaseType.to
StrongMBON2CXTargetsToPostInFB$type.from <- factor(StrongMBON2CXTargetsToPostInFB$type.from,levels=unique(StrongMBONTargetInpC$databaseType.to),ordered=TRUE)
StrongMBON2CXTargetsToPostInFB <- arrange(StrongMBON2CXTargetsToPostInFB,type.from)
# Plot and save the StrongMBON2CXTargetsToPostInFB based on the connectionMeasure of "weightRelative"
plotStrongMBON2CXTargetsToPostInFB <- plotConnectivityMatrix(StrongMBON2CXTargetsToPostInFB,byGroup="id")
print(plotStrongMBON2CXTargetsToPostInFB)
ggsave("plotStrongMBON2CXTargetsToPostInFB.eps", plot=plotStrongMBON2CXTargetsToPostInFB, device="eps", path=PlotDir, scale=1,
width=80, height=10, units="in", dpi=300, limitsize=FALSE)
# Get type to type connection table
StrongMBON2CXTargetsToPostInFB$type.from <- as.vector(StrongMBON2CXTargetsToPostInFB$type.from)
StrongMBON2CXTargetsToPostInFB_Type2TypeTab <- getTypeToTypeTable(StrongMBON2CXTargetsToPostInFB)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
# StrongMBON2CXTargetsToPostInFB_Type2TypeTab <- StrongMBON2CXTargetsToPostInFB_Type2TypeTab %>% arrange(type.from %in% StrongMBON2CX_TargetsType)
# Filter the table by weightRelative
StrongMBON2CXTargetsToPostInFB_Type2TypeTab <- StrongMBON2CXTargetsToPostInFB_Type2TypeTab %>% filter(weightRelative > 0.01)
# Exclude connections to self types
StrongMBON2CXTargetsToPostInFB_Type2TypeTab <- StrongMBON2CXTargetsToPostInFB_Type2TypeTab %>% filter(type.from != type.to)
# Arrange StrongMBON2CXTargetsToPostInFB_Type2TypeTab in the order of StrongMBONTargetInpC$databaseType.to
StrongMBON2CXTargetsToPostInFB_Type2TypeTab$type.from <- factor(StrongMBON2CXTargetsToPostInFB_Type2TypeTab$type.from,levels=unique(StrongMBONTargetInpC$databaseType.to),ordered=TRUE)
StrongMBON2CXTargetsToPostInFB_Type2TypeTab <- arrange(StrongMBON2CXTargetsToPostInFB_Type2TypeTab,type.from)
# Plot and save the StrongMBON2CXTargetsToPostInFB_Type2TypeTab based on the connectionMeasure of "weightRelative"
plotStrongMBON2CXTargetsToPostInFB_Type2TypeConn <- plotConnectivityMatrix(StrongMBON2CXTargetsToPostInFB_Type2TypeTab,byGroup="type",connectionMeasure="weightRelative")
print(plotStrongMBON2CXTargetsToPostInFB_Type2TypeConn)
ggsave("StrongMBON2CXTargetsToPostInFB_Type2TypeTable_weightRelative.eps", plot=plotStrongMBON2CXTargetsToPostInFB_Type2TypeConn, device="eps", path=PlotDir, scale=1,
width=11, height=8, units="in", dpi=300, limitsize=TRUE)
# Set up the layout for the pathway plot
types <- unique(c(unique(as.vector(StrongMBON2CXTargetsToPostInFB_Type2TypeTab$type.from)),sort(unique(as.vector(StrongMBON2CXTargetsToPostInFB_Type2TypeTab$type.to))) ) )
numTypes <- length(types)
numFrom <- length(unique(as.vector(StrongMBON2CXTargetsToPostInFB_Type2TypeTab$type.from)))
numTo <- length(unique(as.vector(StrongMBON2CXTargetsToPostInFB_Type2TypeTab$type.to)))
# Arrange the primary MBON->CX targets in a circle
angsFrom <- seq(-pi,pi,length.out = numFrom + 1)
angsFrom <- angsFrom[1:(length(angsFrom)-1)]
xFrom <- 1*sin(angsFrom)
yFrom <- 1*cos(angsFrom)
# Arrange the secondary MBON->CX targets in a bigger circle
angsTo <- seq(-pi,pi,length.out = numTypes - numFrom + 1)
angsTo <- angsTo[1:(length(angsTo)-1)]
xTo <-3*sin(angsTo)
yTo <-3*cos(angsTo)
# xyLookup = data.frame(type = types, x = c(rep(-1,times = numFrom),rep(0,times = numTypes-numFrom)),
# y = c(seq(-1,1,length.out = numFrom), seq(-1,1,length.out = numTypes-numFrom)))
# xyLookup = data.frame(type = types, x = c(xFrom,rep(3,times = numTypes-numFrom)),
# y = c(yFrom, seq(-8,8,length.out = numTypes-numFrom)))
xyLookup = data.frame(type = types, x = c(xFrom,xTo), y = c(yFrom,yTo))
# Graph the TypeToType ConnTable using the xyLookup lookupTable
StrongMBON2CXTargetsToPostInFB_Type2TypeTab$type.from <- as.vector(StrongMBON2CXTargetsToPostInFB_Type2TypeTab$type.from)
gg_MBON1stTo2ndaryTargetTab <- graphConTab_old(StrongMBON2CXTargetsToPostInFB_Type2TypeTab,xyLookup,FALSE,TRUE)
gg_MBON1stTo2ndaryTargetTab <- gg_MBON1stTo2ndaryTargetTab + scale_y_reverse()
print(gg_MBON1stTo2ndaryTargetTab)
ggsave("MBON1stTo2ndaryTargetTab.svg", plot=gg_MBON1stTo2ndaryTargetTab, device="svg", path=PlotDir, scale=1,
width=16, height=16, units="in", dpi=300, limitsize=FALSE)
StrongMBON2CXTargetsToPostInFB_Type2Type_clustered <- plotCorrMatCluster(PlotDir,StrongMBON2CXTargetsToPostInFB_Type2TypeTab,'StrongMBON2CXTargetsToPostInFB_Type2Type')
Using weightRelative as value column: use value.var to override.
StrongMBON2CXTargetsToPostInFB_Type2TypeTab_hcByFrom <- StrongMBON2CXTargetsToPostInFB_Type2Type_clustered[[1]]
StrongMBON2CXTargetsToPostInFB_Type2TypeTab_hcByTo <- StrongMBON2CXTargetsToPostInFB_Type2Type_clustered[[2]]
rm(StrongMBON2CXTargetsToPostInFB_Type2Type_clustered);
# Plot the connections by pathwayWeight (= totalMBContribution * weightRelative)
# Find the postsynaptic partners of secondary StrongMBON2CX_TargetNeurons
StrongMBON2CX_2ndTargetsInFB_Types <- unique(as.vector(StrongMBON2CXTargetsToPostInFB_Type2TypeTab$databaseType.to))
StrongMBON2CX_2ndTargetsInFB_Neurons <- getTypesTable(StrongMBON2CX_2ndTargetsInFB_Types)
StrongMBON2CX_2ndTargetsCnctTable <- getConnectionTable(StrongMBON2CX_2ndTargetsInFB_Neurons$bodyid,synapseType="POST")
# head(StrongMBON2CX_2ndTargetsCnctTable)
StrongMBON2CX_2ndTargetsToPostInFB <- getConnectionTable_forSubset(StrongMBON2CX_2ndTargetsInFB_Neurons$bodyid, StrongMBON2CX_2ndTargetsCnctTable$to,"FB")
# Arrange StrongMBON2CXTargetsToPostInFB in the order of StrongMBONTargetInpC$databaseType.to
# StrongMBON2CXTargetsToPostInFB$type.from <- factor(StrongMBON2CXTargetsToPostInFB$type.from,levels=unique(StrongMBONTargetInpC$databaseType.to),ordered=TRUE)
# StrongMBON2CXTargetsToPostInFB <- arrange(StrongMBON2CXTargetsToPostInFB,type.from)
# Plot and save the StrongMBON2CX_2ndTargetsToPostInFB based on the connectionMeasure of "weightRelative"
plotStrongMBON2CX2ndTargetsToPostInFB <- plotConnectivityMatrix(StrongMBON2CX_2ndTargetsToPostInFB,byGroup="id")
print(plotStrongMBON2CX2ndTargetsToPostInFB)
ggsave("plotStrongMBON2CX2ndTargetsToPostInFB.eps", plot=plotStrongMBON2CX2ndTargetsToPostInFB, device="eps", path=PlotDir, scale=1,
width=180, height=80, units="in", dpi=300, limitsize=FALSE)
# Get type to type connection table
StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab <- getTypeToTypeTable(StrongMBON2CX_2ndTargetsToPostInFB)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'roi', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
# StrongMBON2CXTargetsToPostInFB_Type2TypeTab <- StrongMBON2CXTargetsToPostInFB_Type2TypeTab %>% arrange(type.from %in% StrongMBON2CX_TargetsType)
# Filter the table by weightRelative
StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab <- StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab %>% filter(weightRelative > 0.01)
# Exclude connections to self types
StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab <- StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab %>% filter(type.from != type.to)
# Arrange StrongMBON2CXTargetsToPostInFB_Type2TypeTab in the order of StrongMBONTargetInpC$databaseType.to
# StrongMBON2CXTargetsToPostInFB_Type2TypeTab$type.from <- factor(StrongMBON2CXTargetsToPostInFB_Type2TypeTab$type.from,levels=unique(StrongMBONTargetInpC$databaseType.to),ordered=TRUE)
# StrongMBON2CXTargetsToPostInFB_Type2TypeTab <- arrange(StrongMBON2CXTargetsToPostInFB_Type2TypeTab,type.from)
# Plot and save the StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab based on the connectionMeasure of "weightRelative"
plotStrongMBON2CX2ndTargetsToPostInFB_Type2Type <- plotConnectivityMatrix(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab,byGroup="type",connectionMeasure="weightRelative")
print(plotStrongMBON2CX2ndTargetsToPostInFB_Type2Type)
ggsave("StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTable_weightRelative.eps", plot=plotStrongMBON2CX2ndTargetsToPostInFB_Type2Type, device="eps", path=PlotDir, scale=1,
width=24, height=16, units="in", dpi=300, limitsize=FALSE)
# Set up the layout for the pathway plot
types <- unique(c(unique(as.vector(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab$type.from)),sort(unique(as.vector(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab$type.to))) ) )
numTypes <- length(types)
numFrom <- length(unique(as.vector(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab$type.from)))
numTo <- length(unique(as.vector(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab$type.to)))
# Arrange the secondary MBON->CX targets in a circle
angsFrom <- seq(-pi,pi,length.out = numFrom + 1)
angsFrom <- angsFrom[1:(length(angsFrom)-1)]
xFrom <- 4*sin(angsFrom)
yFrom <- 4*cos(angsFrom)
# Arrange the tertiary MBON->CX targets in a bigger circle
angsTo <- seq(-pi,pi,length.out = numTypes - numFrom + 1)
angsTo <- angsTo[1:(length(angsTo)-1)]
xTo <-5*sin(angsTo)
yTo <-5*cos(angsTo)
# xyLookup = data.frame(type = types, x = c(rep(-1,times = numFrom),rep(0,times = numTypes-numFrom)),
# y = c(seq(-1,1,length.out = numFrom), seq(-1,1,length.out = numTypes-numFrom)))
# xyLookup = data.frame(type = types, x = c(xFrom,rep(3,times = numTypes-numFrom)),
# y = c(yFrom, seq(-8,8,length.out = numTypes-numFrom)))
xyLookup = data.frame(type = types, x = c(xFrom,xTo), y = c(yFrom,yTo))
# Graph the TypeToType ConnTable using the xyLookup lookupTable
gg_MBON2ndTo3rdTargetTab <- graphConTab_old(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab,xyLookup,FALSE,TRUE)
gg_MBON2ndTo3rdTargetTab <- gg_MBON2ndTo3rdTargetTab + scale_y_reverse()
print(gg_MBON2ndTo3rdTargetTab)
ggsave("MBON2ndTo3rdCXTargetTab.svg", plot=gg_MBON2ndTo3rdTargetTab, device="svg", path=PlotDir, scale=1,
width=30, height=30, units="in", dpi=300, limitsize=FALSE)
StrongMBON2CX_2ndTargetsToPostInFB_Type2Type_clustered <- plotCorrMatCluster(PlotDir,StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab,'StrongMBON2CX_2ndTargetsToPostInFB_Type2Type')
Using weightRelative as value column: use value.var to override.
StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo <- StrongMBON2CX_2ndTargetsToPostInFB_Type2Type_clustered[[2]]
# Set up the layout for the pathway plot
types <- unique(c(unique(as.vector(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo$type.from)),unique(as.vector(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo$type.to))))
numTypes <- length(types)
numFrom <- length(unique(as.vector(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo$type.from)))
numTo <- length(unique(as.vector(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo$type.to)))
xyLookup = data.frame(type = types, x = c(rep(-1,times = numFrom),rep(0,times = numTypes-numFrom)), y = c(seq(-1,1,length.out = numFrom), seq(-1,1,length.out = numTypes-numFrom)))
# Graph the TypeToType ConnTable using the lookupTable
StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo_copy <- StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo
StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo_copy$type.to <- as.vector(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo_copy$type.to)
StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo_pathway <- graphConTab_old(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo_copy,xyLookup,FALSE,TRUE)
# gg_MBON2TargetTab <- graphConTabPolyChrome(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo_pathway,xyLookup,FALSE,TRUE)
StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo_pathway <- StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo_pathway + scale_y_reverse()
print(StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo_pathway)
ggsave("StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_clusterByTo_pathway.svg", plot=StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab_hcByTo_pathway, device="svg", path=PlotDir, scale=1,
width=30, height=60, units="in", dpi=300, limitsize=FALSE)
ran well up to here
# Run t-SNE on the type.to of StrongMBON2CX_2ndTargetsToPostInFB_Type2TypeTab
# library(M3C)
# tsne(Data4Clust,perplex=15)
# Plot neuron to neuron connection matrix from MBONs to non-CX non-MBON targets
MBON_nonCXnonMBON_ConnTable <- MBON_PostConnections %>% filter(type.to %in% MBONnonCXTargetsL)
plotMBON_nonCXnonMBON_ConnTable <- plotConnectivityMatrix(MBON_nonCXnonMBON_ConnTable,byGroup="id",connectionMeasure="weightRelative")
print(plotMBON_nonCXnonMBON_ConnTable)
# Plot type to type connection matrix from MBONs to non-CX non-MBON targets
MBON_nonCXnonMBON_Type2TypeTab <- getTypeToTypeTable(MBON_nonCXnonMBON_ConnTable)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'roi', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'roi', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
# Filter the table by weightRelative
MBON_nonCXnonMBON_Type2TypeTab <- MBON_nonCXnonMBON_Type2TypeTab %>% filter(weightRelative > 0.01)
plotMBON_nonCXnonMBON_Type2TypeConn <- plotConnectivityMatrix(MBON_nonCXnonMBON_Type2TypeTab,byGroup="type",connectionMeasure="weightRelative")
print(plotMBON_nonCXnonMBON_Type2TypeConn)
# Plot neuron to neuron connection matrix from MBON non-CX non-MBON targets to their targets in the CX
MBON_nonCXnonMBON_2ndaryCX_ConnTable <- MBON_2ndaryPostConnections %>% filter(type.to %in% MBONCX2ndaryTargetsL)
plotMBON_nonCXnonMBON_2ndaryCX_ConnTable <- plotConnectivityMatrix(MBON_nonCXnonMBON_2ndaryCX_ConnTable,byGroup="id",connectionMeasure="weightRelative")
print(plotMBON_nonCXnonMBON_2ndaryCX_ConnTable)
# Plot type to type connection matrix from MBON non-CX non-MBON targets to their targets in the CX
MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab <- getTypeToTypeTable(MBON_nonCXnonMBON_2ndaryCX_ConnTable)
`summarise()` ungrouping output (override with `.groups` argument)
`summarise()` regrouping output by 'to', 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'roi', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3', 'supertype.from3' (override with `.groups` argument)
`summarise()` regrouping output by 'type.from', 'type.to', 'databaseType.to', 'databaseType.from', 'outputContributionTotal', 'previous.type.to', 'previous.type.from', 'roi', 'outputContribution', 'supertype.to1', 'supertype.from1', 'supertype.to2', 'supertype.from2', 'supertype.to3' (override with `.groups` argument)
# Filter the table by weightRelative
MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab <- MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab %>% filter(weightRelative > 0.01)
# Exclude connections to self types
MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab <- MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab %>% filter(type.from != type.to)
plotMBON_nonCXnonMBON_2ndaryCX_Type2TypeTab <- plotConnectivityMatrix(MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab,byGroup="type",connectionMeasure="weightRelative")
print(plotMBON_nonCXnonMBON_2ndaryCX_Type2TypeTab)
# Filter MBON_nonCXnonMBON_Type2TypeTab based on type.to with direct connections in the CX
MBON_nonCXnonMBONwCX2ndT_Type2TypeTab <- MBON_nonCXnonMBON_Type2TypeTab %>% filter(type.to %in% unique(MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab$type.from))
MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab <- MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab %>% filter(type.from %in% unique(MBON_nonCXnonMBONwCX2ndT_Type2TypeTab$type.to))
# Plot pathways from MBONs to non-CX non-MBON targets to secondary CX targets
# Combine tables
MBON_nonCXnonMBON_2ndaryCX_Type2TypeComboTab <- bind_rows(MBON_nonCXnonMBONwCX2ndT_Type2TypeTab,MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab, .id = NULL)
# Set up the layout for the pathway plot
types <- unique(c(unique(as.vector(MBON_nonCXnonMBONwCX2ndT_Type2TypeTab$type.from)), unique(as.vector(MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab$type.from)),
unique(as.vector(MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab$type.to))))
numTypes <- length(types)
numMBONs <- length(unique(as.vector(MBON_nonCXnonMBONwCX2ndT_Type2TypeTab$type.from)))
numMidNodes <- length(unique(as.vector(MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab$type.from)))
numCXtargets <- length(unique(as.vector(MBON_nonCXnonMBON_2ndaryCX_Type2TypeTab$type.to)))
xyLookup = data.frame(type = types, x = c(rep(-1,times = numMBONs), rep(0,times = numMidNodes), rep(1,times = numCXtargets)),
y = c(seq(-1,1,length.out = numMBONs), seq(-1,1,length.out = numMidNodes), seq(-1,1,length.out = numCXtargets)))
# Graph the TypeToType ConnTable using the lookupTable
MBON_nonCXnonMBON_2ndaryCX_Type2TypeComboPath <- graphConTab_old(MBON_nonCXnonMBON_2ndaryCX_Type2TypeComboTab,xyLookup,FALSE,TRUE)
MBON_nonCXnonMBON_2ndaryCX_Type2TypeComboPath <- MBON_nonCXnonMBON_2ndaryCX_Type2TypeComboPath + scale_y_reverse()
# print(MBON_nonCXnonMBON_2ndaryCX_Type2TypeComboPath)
ggsave("MBON_nonCXnonMBON_2ndaryCX_Type2TypeComboPath.svg", plot=MBON_nonCXnonMBON_2ndaryCX_Type2TypeComboPath, device="svg", path=PlotDir, scale=1,
width=30, height=45, units="in", dpi=300, limitsize=FALSE)
MBON2ndaryCXTargetTypes <- unique(as.vector(MBON2ndaryTargetInp$databaseType.to))
Focus on the FB now (the only exception is LCNp which can probably be treated separately) and try to compute a “pathway weight” per CX target type. For every connection, MBONInfluence is the product of the relative weight with the total contribution of MBONs to the presynaptic neuron. pathwaysWeight is the sum of that over a target type (basically the sum of all its indirect MBON influences).
***Should also find pathways through middle neurons outside of the CX.
MBONTargetFBOut <- MBONTargetBagLat$outputs %>% filter(roi=="FB" & type.from %in% MBONTargetInpC$type.to) %>%
mutate(MBONInfluence = MBONTargetInpC$totalMBContribution[match(type.from,MBONTargetInpC$type.to)]*weightRelative) %>% group_by(type.to) %>% mutate(pathwaysWeight = sum(MBONInfluence)) %>% ungroup()
Looking at this table and sorting it according to various ways, the things that first pops out is that it’s mostly a FB tangential network (meaning most FB tangential neuron targets in the FB are other FB tangential neurons, I guess something reminiscent of the ring neurons). So we’d need a way to wean this recurrence in the way we consider which parts of the network are influenced by the MBONs.
MBONTargetFBOutSummary <- MBONTargetFBOut %>% group_by(type.to) %>% summarise(pathwaysWeight = pathwaysWeight[1])
Considering FB4R separately
MBONTargetFB4R <- MBONTargetFBOut %>% filter(type.from == "FB4R_R") %>% group_by(type.to) %>% summarise(pathwaysWeight = pathwaysWeight[1])
Suggestion: redo that, but study the pool of neurons influenced by a single MBON type at a time.
Other axis to explore: FB tangential inhomogeneous inputs onto columnar neurons.